<template>
  <div class="container">
    <div class="demand-list" v-loading="loading" v-if="loading || listData.length">
      <div
        class="demand-item"
        v-for="(item, index) in listData" 
        @click="toDemandDetail(item.id)"
        :key="item.id"
      >
        <div class="title">{{item.demandTitle}}</div>
        <div class="content">{{ item.intro }}</div>
        <div class="date">发布时间：{{ item.createTime }}</div>
      </div>
    </div>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <div style="padding:200px 0;text-align:center;" v-if="!listData.length && !loading">暂无数据~</div>
  </div>
</template>

<script>
import { demandHall } from "@/api/demand.js";
export default {
  name: "ComponentName",

  data() {
    return {
      queryParams: {
        keyWord: "",
        pageNo: 1,
        pageSize: 10,
      },
      listData: [],
      total: 0,
      loading: true
    };
  },
  created(){
    this.queryParams.keyWord =  this.$route.query.keywords || ''
    this.getList()
  },
  watch:{
    $route(val){
      this.queryParams.pageNo = 1
      this.listData = []
      this.queryParams.keyWord = val.query.keywords
      this.loading = true
      this.getList()
    }
  },
  methods: {
    toDemandDetail(id) {
      this.$router.push("/demandDetail/demandHall/" + id);
    },
    getList() {
      demandHall(this.queryParams).then((res) => {
        this.listData = res.result.records;
        this.total = res.result.total;
        this.loading = false
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.container {
  width: 1200px;
  margin: auto;
}

.demand-list {
    min-height: 700px;

  .demand-item {
    background: #ffffff;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    cursor: pointer;

    .title {
      font-weight: 800;
      font-size: 18px;
      color: #333333;
    }

    .content {
      padding: 12px 0;
      font-weight: 500;
      font-size: 16px;
      color: #808080;
    }

    .date {
      font-weight: 500;
      font-size: 16px;
      color: #999999;
    }
  }

  .demand-item:last-child {
    margin: 0;
  }
}
</style>
